//
//  DDStatusForwardCell.swift
//  SinaMicroBlogSwift2
//
//  Created by dqw on 15/8/3.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class DDStatusForwardCell: DDStatusCell {
    
    override var status: DDStatus? {
        
        didSet {
            
            let name = status?.retweeted_status?.user?.name
            let text = status?.retweeted_status?.text
            let text2 =  "@" + name! + ":" + text!
            forwardLabel.attributedText = DDEmoticonPackage.attributedText(text2, font: forwardLabel.font)
        }
    }

    override func addAndLayoutSubViews() {
        super.addAndLayoutSubViews()
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(forwardLabel, aboveSubview: backButton)
        
       // MARK:-注意此处不能造成循环依赖。
//        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backButton, size: nil, offset: CGPoint(x: DDStatusCellMargin, y: DDStatusCellMargin))
        forwardLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: 0, y: DDStatusCellMargin))
//        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: backButton, attribute: NSLayoutAttribute.Width, multiplier: 1.0, constant: -DDStatusCellMargin * 2))
       let cons =  pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: DDStatusCellMargin))
        
        backButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -DDStatusCellMargin, y: 0))
        backButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottonView, size: nil, offset: CGPoint(x: 0, y: 0))
        
        pictureViewHeightCont = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureViewWidthCont = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width )
        pictureViewTopCont = pictureView.ff_Constraint(cons
            , attribute: NSLayoutAttribute.Top )
    }
    
    private lazy var forwardLabel:UILabel = {
        
        let label = UILabel()
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - DDStatusCellMargin * CGFloat(2)
        
        return label
    }()
    
    private lazy var backButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        return button
    }()
}
